package com.example.yichuangyun.mvvm.ui.activity.view;

import androidx.lifecycle.MutableLiveData;

import com.example.yichuangyun.config.Constant;
import com.example.yichuangyun.model.contacts.AddContactsParamsModel;
import com.example.yichuangyun.mvvm.base.BaseViewModel;
import com.example.yichuangyun.mvvm.di.retrofit.BaseModel;
import com.example.yichuangyun.mvvm.di.retrofit.BaseNetCallback;

public class ContactsDetailsViewModel extends BaseViewModel {

    public MutableLiveData<AddContactsParamsModel> detailsModel = new MutableLiveData<>();

    public void getContactsDetails(String contactId, int examine) {
        addSubscribe(mRetrofitHelper.getContactsDetails(contactId, examine).subscribeWith(new BaseNetCallback<AddContactsParamsModel>() {
            @Override
            public void onSuccess(BaseModel<AddContactsParamsModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode()) {
                    detailsModel.setValue(baseModel.getData());
                } else {
                    mErrorData.setValue(baseModel.getMsg());
                }
            }

            @Override
            public void onError(String message) {
                super.onError(message);
                mErrorData.setValue(message);
            }
        }));
    }
}
